﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SubmitOrder.aspx.cs" Inherits="WeChat.MenuReservation.SubmitOrder" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
    <title>提交订单</title>
    <script src="../../Script/rem.js"></script>
    <script src="../../Script/jquery.min.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../../css/base.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/page.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/all.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/loaders.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/loading.css"/>
    <script src="../../Script/jquery-1.8.3.min.js"></script>
    <link href="../../Script/slick/slick.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css"/>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>  

</head>
    <!--loading页开始-->
<div class="loading">
	<div class="loader">
        <div class="loader-inner pacman">
          <div></div>
          <div></div>
          <div></div>
          <div></div>
          <div></div>
        </div>
	</div>
</div>
<!--loading页结束-->
<body>
<%--		<header class="mui-bar mui-bar-nav report-header box-s" id="header">
			<a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a>
			<p>提交订单</p>
	    </header>--%>
	    <div id="main" class="mui-clearfix contaniner sorder">	    	
	    	<div class="warning clearfloat box-s">
    			提示：请在15分钟内完成在线支付，逾期订单将删除
    		</div>
    		<div class="odernum clearfloat">
    			<ul>
    				<li >您的订单号：<span id="orderid" style="color:black"></span></li>
    				<li>应付金额：<span id="sum"></span></li>
    			</ul>
    		</div>

    		<div class="pay-method clearfloat">
    			<ul>
    				<li>请选择支付方式</li>
    			</ul>
    		</div>
	    	<div class="addlist clearfloat">
	    <%--		<div class="bottom clearfloat box-s">
	    			<section class="shopcar clearfloat">
						<div class="radio radiosss fr"> 
						    <label  id="wx">
						        <input type="radio" name="sex" value="" />
						        <div class="option"></div>
						    </label>
						</div>
						<div class="sorder-list clearfloat fl">
							<i class="iconfont icon-weixinzhifu fl"></i>
							<div class="zuo fl">
								<p class="tit">微信支付</p>
								<p class="fu-tit">亿万用户的选择，更快更安全</p>
							</div>							
						</div>
					</section>
	    		</div>--%>
	    		<div class="bottom clearfloat box-s">
	    			<section class="shopcar clearfloat">
						<div class="radio radiosss fr" > 
						    <label id="ye">
						        <input type="radio" name="sex" value="" checked="checked" />
						        <div class="option"></div>
						    </label>
						</div>
						<div class="sorder-list clearfloat fl">
							<i class="iconfont icon-yinxingqia fl"></i>
							<div class="zuo fl">
								<p class="tit">卡内余额</p>
								<p class="fu-tit">卡内余额直接支付，方便快捷！</p>
							</div>	
                            
                            

						</div>
					</section>
	    		</div>

                             <div class="odernum clearfloat" >
								<%--<ul>
                                	<li><input type="checkbox" id = "jf" value="1" name="jf1">积分抵扣!!!</li>
								</ul>--%>
                           	</div>	
                            <div class="odernum clearfloat">
    			                <ul>    
                                    <li id="optionss" style="display:none;">超市配送选项：<input type="radio" name="opon" class="chaoshi03" id="opid01" checked="checked" value="自取" />自取&nbsp;  <input class="chaoshi04" id="opid02" type="radio" name="opon" value="配送" />配送</li>
                                    <li id="ade1" style="display:none;">请选择地址：
                                        <select id="address1">
                                            <option value="">请选择</option>
                                            <option value="西安大路810号">西安大路810号</option>
                                            <option value="南昌路318号">南昌路318号</option>
                                        </select>
                                    </li>
			                        <li id="rdo" style="display:none;">超市取货时段：<input type="radio" name="NAS" class="chaoshi01" checked="checked" value="12:00-13:30" />12:00-13:30&nbsp;  <input class="chaoshi02" type="radio" name="NAS" value="17:30-18:30" />17:30-18:30 </li>
                                    <li id="ade">请输入地址：<input type='text' id='address' name='address' runat='server' placeholder='请输入您的地址' value="111" /></li>
			                        <li>联系电话：<input type='text' id='telnum' name='telnum' maxlength="11" runat='server' placeholder='请输入您的电话' /></li>
    			                </ul>
    		                </div>
          

	    	</div>
	    	<a href="#" class="address-add fl" onclick="submit()">
	     		确认支付
	     	</a>
	    </div>
	    

  <div class="weui-skin_android" id="weui-android-actionsheet"  style="display: none">
        <div class="weui-mask"></div>
        <div class="weui-actionsheet">
            <div class="weui-actionsheet__menu">
                <div class="" style="padding:2%">余额不足，请选择微信支付或者给卡充值</div>
                <div class="weui-actionsheet__cell" style="text-align:center" onclick="javascript:$('#weui-android-actionsheet').hide();">微信支付</div>
                <div class="weui-actionsheet__cell"  style="text-align:center">余额充值</div>
                 <div class="weui-actionsheet__cell"  style="text-align:center" onclick="javascript:$('#weui-android-actionsheet').hide();">取消</div>
            </div>
        </div>
    </div>
   <div style="display: none;"   id="dialog">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd">订餐成功！</div>
        <div class="weui-dialog__ft">
            <a  href="../../MenuReservation/ReserveMenu.aspx"" class="weui-dialog__btn weui-dialog__btn_primary" id="que">确定</a>
        </div>
    </div>
</div>
	</body>


	<script type="text/javascript" src="../../Script/jquery-1.8.3.min.js" ></script>
	<script src="../../Script/fastclick.js"></script>
	<script src="../../Script/mui.min.js"></script>
	<script type="text/javascript" src="../../Script/hmt.js" ></script>

    <script type="text/javascript">
        function getUrlParam(price) {
            var reg = new RegExp("(^|&)" + price + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        $(window).load(function () {
            $(".loading").addClass("loader-chanage")
            $(".loading").fadeOut(300)
        })
        var openid;
        var canteen = "";
        $(function () {

            //显示地址电话
            var opid = getUrlParam('openid');
            var address = $("#address").val();
            var telnum = $("#telnum").val();
            $.ajax({
                url: "../../AjaxSets.ashx",
                type: "post",
                data: { opid: opid, functionName: "torage" },
                success: function (data) {

                    var item = $.parseJSON(data);
                    $("#address").val(item[0].address);
                    //alert("address"+item[0].address+"111");
                    $("#telnum").val(item[0].telnum);
                },
                error: function (data) {
                    alert("异常！");
                }
            });



            $("#sum").html(getUrlParam('price'));
            $("#orderid").html(getUrlParam('OrderID'));

            $("#address").html(getUrlParam('address'));
            $("#telnum").html(getUrlParam('telnum'));
            openid = getUrlParam('openid');

            var orderid = getUrlParam('OrderID');
            console.log(orderid);
            $.ajax({
                url: "../../AjaxSets.ashx",
                type: "post",
                data: { orderid: orderid, functionName: "getcanteen" },
                success: function (data) {

                    var item = $.parseJSON(data);
                    canteen = item[0].canteen;
                    console.log("类型：" + canteen);
                    if (canteen == "超市") {
                        $("#rdo").css("display", "block");
                        $("#optionss").css("display", "block");
                        $("#ade").css("display", "none");
                    }
                    else
                    {                        
                        $("#ade").css("display", "none");
                    }


                },
                error: function (data) {
                    alert("异常！");
                }
            });



        });

        if (canteen == "超市") {

            $("#rdo").css("display", "block");
            $("#optionss").css("display", "block");
            $("#ade").css("display", "none");
        }
        else {
            $("#rdo").css("display", "none");
            $("#optionss").css("display", "none");
            $("#ade").css("display", "none");
        }


        var optin = "";
        //获取点击事件
        // 点击单选按钮后触发，即，我们选择“男”时，触发一个事件，弹出选中的值
        $("input[name=opon]").click(function () {
            optin = $(this).val();
            //alert(optin);
            if ("自取" == optin) {
                $("#rdo").css("display", "block");
                $("#ade").css("display", "none");
                $("#ade1").css("display", "none");
            }
            else {
                $("#rdo").css("display", "none");
                $("#ade").css("display", "none");
                $("#ade1").css("display", "block");
            }
        });




        function submit() {
            var sum = $("#sum").text();
            var orderid = $("#orderid").text();
            //var address = document.getElementById("address").value;
            var address = "";


            var telnum = document.getElementById("telnum").value;

            var address2 = "";
            if (canteen == "超市") {
              //  address2 = $("input[name='NAS']:checked").val();

                var address03 = $("input[name='opon']:checked").val();
              //  console.log("获取提交时选中的值：" + address03);
                if (address03 == "自取") {
                    address = $("input[name='NAS']:checked").val();
                }
                else
                {
                    address = $("#address1").val();
                    //console.log("配送选中的值：" + address);
                }
            }
            else {
                address2 = "";
                address = document.getElementById("address").value;
            }



            if (document.getElementById("telnum").value == "") {
                alert("电话不能为空哦！");
                return false;
            }

            if (address == "") {
                alert("地址不能为空哦！");
                return false;
            }

            var jf = $("#jf").prop("checked");
            if (jf) {

                var jfzt = $("#jf").prop("checked")

            };
            debugger
            var seldate_dummy = getUrlParam('seldate_dummy');
            //if (seldate_dummy == "" || seldate_dummy == null) {
            //    alert("下单日期未获取成功，返回重新下单！");
            //    return false;
            //}
            // debugger
            $.ajax({
                type: "post",
                url: "../../MenuReserveHandler.ashx",
                dataType: "json",
                async: false,
                data: { orderid: orderid, seldate_dummy: seldate_dummy, canteen: canteen, openid: openid, funcName: "meulimitnumorder" },
                success: function (data) {
                    if (data == false && canteen == "超市") {
                        alert("此订单某商品份数已售完，无法支付，不变之处，敬请谅解！");
                        return false;
                    }
                    else if (data == false && canteen != "超市") {        
                        alert("此时段订餐餐次已达上限，无法再次购买，不便之处敬请谅解！");
                        return false;
                    }
                    else {

                        if ($('#wx input:radio[name="sex"]:checked').val() != null) {

                            var ss = "";
                            $.ajax({

                                type: "post",
                                url: "../../MenuReserveHandler.ashx",
                                async: false,
                                data: { address: address, address2: address2, telnum: telnum, funcName: 'wxaddress', orderid: orderid, openid: openid },
                                success: function (data) {

                                },
                                //error: function () {
                                //    alert("异常！");
                                //},
                            });

                            var attach = "Reservation";
                            // window.location.href = "WxPay.aspx?openid=" + openid + "&total_fee=" + sum + "&attach=" + attach + "&orderid=" + orderid + "&address" + address;
                            var wxopenid = getUrlParam('wxopenid');
                            window.location.href = "WxPay.aspx?openid=" + wxopenid + "&total_fee=" + sum + "&attach=" + attach + "&orderid=" + orderid;

                        }
                        if ($('#ye input:radio[name="sex"]:checked').val() != null) {

                            $.ajax({
                                type: "post",
                                url: "../../MenuReserveHandler.ashx",
                                async: false,
                                data: { address: address, address2: address2, jfzt: jfzt, telnum: telnum, price: sum, funcName: 'yePay', orderid: orderid, openid: openid, canteen: canteen },
                                success: function (data) {
                                    if (data == "SUCCESS") {

                                        $("#dialog").css("display", "block");
                                        //  window.location.href = "../../MenuReservation/ReserveMenu.aspx";
                                    }

                                    if (data == "-1") {

                                        alert("正在订餐，请稍后！");
                                        //  window.location.href = "../../MenuReservation/ReserveMenu.aspx";
                                    }
                                    if (data == "fail") {
                                        $("#weui-android-actionsheet").css("display", "block");
                                    }
                                },
                                error: function () {
                                    alert("异常！");
                                }
                            });
                        }
                    }
                }
            })


        }
    </script>

</html>











